package myapp.DAO;

import myapp.EnumAndConstans.Constants;
import myapp.EnumAndConstans.RequestMethod;
import android.util.Log;

public class DataProvider {
	public static String dbBaseHost;
	public static String chatBaseHost;
	
	public String requestGET(String url){
		Log.i("DataProvider", "[requestGET] " + url);
		String responseString = null;
		
		RestClient client = new RestClient(url);
		
		try {
			client.Execute(RequestMethod.GET);
			Log.i("DataProvider", "[requestGET] Executed!");
		} catch (Exception e) {
			// TODO: handle exception
			Log.e("DataProvider", "[requestGET] Exception: " + e.getMessage());
			return Constants.USERNAME_NOT_AVAILABLE;
//			e.printStackTrace();
		}
		
		responseString = client.getResponse();
		Log.i("DataProvider", "[requestGET] response: " + responseString);
		return responseString;
	}
	
	public String requestPOST(String url, String data){
		Log.i("DataProvider", "[requestPOST] " + url);
		
		RestClient client = new RestClient(url);
		
		client.AddParam("", data);
		
		try {
			client.Execute(RequestMethod.POST);
			Log.i("", "[requestPost] response: " + client.getResponse() + " " + client.getErrorMessage());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Log.i("DataProvider", "[requestPOST] " + e.getMessage()+ "" + e.getLocalizedMessage());
			return null;
		}
		return client.getResponse();
	}
}
